package ua.openmedis.web.assets;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import ua.openmedis.domain.AssetGenericName;
import ua.openmedis.service.api.AssetService;
import ua.openmedis.service.impl.AssetServiceImpl;
import ua.openmedis.web.umdns.UmdnsController;

@SessionScoped
@ManagedBean(name = "assetsController")
public class AssetsController {
	private AssetsViewBean viewBean = new AssetsViewBean();

	private AssetService assetService = new AssetServiceImpl();

	private AssetsTable assetsTable = new AssetsTable();

	@ManagedProperty(value = "#{umdnsController}")
	private UmdnsController umdnsController;

	@PostConstruct
	public void postConstract() {
		
	}

	public void setUmdns() {
		AssetGenericName umdns = umdnsController.getUmdnsTable()
				.getSelectedUmdns();
		viewBean.getCurrentAsset().setUmdns(umdns);
	}

	public void saveCreatedAsset() {
		FacesContext.getCurrentInstance().addMessage(
				null,
				new FacesMessage(FacesMessage.SEVERITY_WARN, "Create asset",
						"Sorry, not implemented yet."));
	}

	
	public void findAssets(){
		assetsTable.setAssetsList(assetService.findAssets(40));
	}

	// --------------- Getters Setters ----------------------------------------
	public AssetsViewBean getViewBean() {
		return viewBean;
	}

	public void setViewBean(AssetsViewBean viewBean) {
		this.viewBean = viewBean;
	}

	public UmdnsController getUmdnsController() {
		return umdnsController;
	}

	public void setUmdnsController(UmdnsController umdnsController) {
		this.umdnsController = umdnsController;
	}

	public AssetsTable getAssetsTable() {
		return assetsTable;
	}

	public void setAssetsTable(AssetsTable assetsTable) {
		this.assetsTable = assetsTable;
	}

}
